#ifndef QUERYPACKAGE_H
#define QUERYPACKAGE_H
#include <QDate>
#include <QString>
#include <QJsonObject>
#include <QList>
#include <QJsonArray>
#include "Enums.h"
class QueryPackage
{
public:
    QueryPackage(QString id,int typr):userid(id),qrytype((type)typr){}
    QString userid = "0";
    type qrytype;
    virtual QString getSource()const{ return "";}
    virtual QString getDest()const{return "";}
    virtual QJsonObject toJson()const;
    QueryPackage(const QueryPackage& other) = default;
    virtual ~QueryPackage(){}
    static QString TypetoString(type f){
        QString typet;
        switch(f){
        case OneWay:{
            typet = "OneWay";
            break;
        }
        case RoundTrip:{
            typet = "RoundTrip";
            break;
        }
        case Tranfer:{
            typet = "Transfer";
            break;
        }
        case Refund:{
            typet = "Refund";
            break;
        }
        case OnTime:{
            typet = "OnTime";
            break;
        }
        case CheckPoint:{
            typet = "CheckPoint";
            break;
        }
        case OnSale:{
            typet = "OnSale";
            break;
        }
        default:{
            typet = "UnKnown";
            break;
        }
        }
        return typet;
    }
#include <QString>

    // 枚举 → 字符串：完全返回枚举名原文（大小写、拼写与枚举一致）
    static QString VehicleToString(Vehicle vehicle) {
        switch (vehicle) {
        case HighFirstClass:    return "HighFirstClass";  // 与枚举名完全一致
        case HighSecondClass:   return "HighSecondClass";
        case QuickFirstClass:   return "QuickFirstClass";
        case QuickSecondClass:  return "QuickSecondClass";
        case SoftBed:           return "SoftBed";
        case HardBed:           return "HardBed";
        case SoftSeat:          return "SoftSeat";
        case HardSeat:          return "HardSeat";
        case FlyFirstClass:     return "FlyFirstClass";
        case FlySecondClass:    return "FlySecondClass";
        case CarSeat:           return "CarSeat";
        case Unknown:           return "Unknown";
        default:                return "Unknown";  // 兼容未来扩展的枚举值
        }
    }

    // 字符串 → 枚举：大小写敏感，仅完全匹配枚举名才有效（无任何格式预处理）
    static Vehicle StringToVehicle(const QString& str) {
        // 严格匹配，大小写、拼写必须与枚举名完全一致
        if (str == "HighFirstClass") {
            return HighFirstClass;
        } else if (str == "HighSecondClass") {
            return HighSecondClass;
        } else if (str == "QuickFirstClass") {
            return QuickFirstClass;
        } else if (str == "QuickSecondClass") {
            return QuickSecondClass;
        } else if (str == "SoftBed") {
            return SoftBed;
        } else if (str == "HardBed") {
            return HardBed;
        } else if (str == "SoftSeat") {
            return SoftSeat;
        } else if (str == "HardSeat") {
            return HardSeat;
        } else if (str == "FlyFirstClass") {
            return FlyFirstClass;
        } else if (str == "FlySecondClass") {
            return FlySecondClass;
        } else if (str == "CarSeat") {
            return CarSeat;
        } else if (str == "Unknown") {
            return Unknown;
        } else {
            return Unknown;  // 任何不匹配的情况（包括大小写错误、拼写错误）都返回 Unknown
        }
    }
};
class OneWayQuery:public QueryPackage{
    //Q_OBJECT
public:
    QString dst = "test";
    QString src = "test";
    QDate start = QDate::currentDate();
    Role r_psg = Role::student;
    QList<Vehicle> t_train;
    OneWayQuery():QueryPackage(0,OneWay){}
    OneWayQuery(QString id,QString dst,QString src,QDate start,int r,const QList<Vehicle>& t):QueryPackage(id,OneWay),dst(dst),src(src),start(start),r_psg((Role)r),t_train(t){}
    virtual QJsonObject toJson()const override;
    QString getSource()const override{return src;}
    QString getDest()const override{return dst;}
    OneWayQuery(const OneWayQuery& other) = default;
};
class RoundTripQuery:public QueryPackage{
public:
    QString dst;
    QString src;
    QDate start;
    QDate end;
    Role r_psg;
    QList<Vehicle> t_train;
    QString getSource()const override{return src;}
    QString getDest()const override{return dst;}
    RoundTripQuery(QString id,QString dst,QString src,QDate start,QDate end,int r,const QList<Vehicle>& t):QueryPackage(id,RoundTrip),dst(dst),src(src),start(start),end(end),r_psg((Role)r),t_train(t){}
    QJsonObject toJson()const  override;
};
class TranferQuery:public QueryPackage{
public:
    QString dst = "Test";
    QString src = "Test";
    QDate start = QDate::currentDate();
    //QDate end;
    Role r_psg = Role::adult;
    QList<Vehicle> t_train;
    QString getSource()const override{return src;}
    QString getDest()const override{return dst;}
    TranferQuery(QString id="0"):QueryPackage(id,Tranfer){}
    TranferQuery(QString id,QString dst,QString src,QDate start,int r,const QList<Vehicle>& t):QueryPackage(id,Tranfer),dst(dst),src(src),start(start),r_psg((Role)r),t_train(t){}
    QJsonObject toJson()const  override;
    TranferQuery(const TranferQuery&) = default;
};
class RefundQuery:public QueryPackage{
public:
    int refundtype;
    QString keyword;
    QString keywordtype;
    QDate start;
    QDate end;
    RefundQuery(QString id,int ty,QDate start,QDate end,QString key,QString type):QueryPackage(id,Refund),refundtype(ty),keyword(key),keywordtype(type),start(start),end(end){}
    QJsonObject toJson()const  override;
    RefundQuery(const RefundQuery&) = default;
};
class OnTimeQuery:public QueryPackage{
public:
    QString station;
    QString trainid;
    OnTimeQuery(QString id,QString station,QString trainid):QueryPackage(id,OnTime),station(station),trainid(trainid){}
    QJsonObject toJson()const override;
    OnTimeQuery(const OnTimeQuery&) = default;
};
class CheckPointQuery:public QueryPackage{
public:
    QString station;
    QString train_id;
    QDate start;
    CheckPointQuery(QString id,QString station,QString train_id,QDate start):QueryPackage(id,CheckPoint),station(station),train_id(train_id),start(start){}
    QJsonObject toJson()const override;
    CheckPointQuery(const CheckPointQuery&) = default;
};
class OnSaleQuery:public QueryPackage{
public:
    QString station;
    QDate start;
    OnSaleQuery(QString id,QString station,QDate start):QueryPackage(id,OnSale),station(station),start(start){}
    QJsonObject toJson()const override;
    OnSaleQuery(const OnSaleQuery&) = default;
};
Q_DECLARE_METATYPE(QueryPackage*)
Q_DECLARE_METATYPE(OneWayQuery*)
Q_DECLARE_METATYPE(RoundTripQuery*)
Q_DECLARE_METATYPE(TranferQuery*)
Q_DECLARE_METATYPE(RefundQuery*)
Q_DECLARE_METATYPE(OnTimeQuery*)
Q_DECLARE_METATYPE(CheckPointQuery*)
Q_DECLARE_METATYPE(OnSaleQuery*)
#endif // QUERYPACKAGE_H
